<!DOCTYPE >
<html lang="zh-cn">
<head>
		<title>后台管理-评论</title>
    <% include ./partials/head %>
    <script type="text/javascript">
      var oComment ={
            operator:function(){
                $(".delete").on('click',function(){
                    $this = $(this)
                    if(window.confirm('你确定删除该评论吗？')){
                        $.post("/admin/comment/delete",{
                            "commentId":$this.attr('commentId'),
                        },function(json){
                            if(json.code==0){
                                $this.parents("tr").remove();
                            }else{
                                alert(json.msg);
                            }
                        },'json');
                    }else{
                        //取消
                    }
                })
                $('.checkall').on('click',function(){
                    var ids=[];
                    $('.item').each(function(){
                        ids.push($(this).attr("commentId"));
                    })
                    $.post("/admin/comment/check",{
                        "commentIds":ids,
                    },function(json){
                        history.go(0);
                    },'json');
                })
            },
            change:function(){
                var state =window.location.href.split("=")[1];
                if(state ==1){
                    $(".title_info").html("已审");
                }else{
                    $(".title_info").html("未处理");
                }
                $("#comment-filter").on("change",function(){
                    var value = $(this).children('option:selected').val(); 
                    window.location.href="/admin/comment?status="+value;
                })
            },
            init:function(){
                this.operator();
                this.change();
            }
        }
        $(document).ready(function(){
            oComment.init();
        })
    </script>
</head>
<body>
	<header>
    <% include ./partials/header %>
  </header>
  <div class="ch-container">
    <div class="row">
      <% include ./partials/sidebar %>
      <!-- 页面内容 -->
      <div id="content" class="col-lg-10 col-sm-10">
        <div class="row">
          <div class="box col-md-12">
            <div class="box-inner">
              <div class="box-header well" data-original-title="">
                <div class="control-group">
                  <div class="controls">
                    <label class="control-label" for="selectError">筛选:&nbsp&nbsp&nbsp </label>
                    <select id="comment-filter" data-rel="chosen">
                      <option>选择</option>
                      <option value="0">未处理</option>
                      <option value="1" >已审</option>
                    </select>
                    <span class="btn btn-default pull-right checkall" >
                     <i class="glyphicon glyphicon-check green"></i> 审核该页
                    </span>
                  </div>
              </div>
              </div>

              <div class="box-content">
                  <div class="alert alert-info center title_info"></div>
                <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                  <thead>
                    <tr>
                      <th></th>
                      <th>评论人</th>
                      <th>评论人ID</th>
                      <th>评论信息</th>
                      <th>评论时间</th>
                      <th>处理情况</th>
                    </tr>
                  </thead>

                  <tbody>
                    <% if (typeof comments != "undefined") { %>
                      <% comments.forEach(function(comment,index) { %>
                        <tr class="item" commentId="<%=comment.id%>">
                          <% if(comment.get("user")!=null){ %>
                          <td class="center"><%=index%></td>
                          <td><a href="/admin/userinfo?userId=<%= comment.get('user').id%>"><%=comment.get("user").get("nickname")%></a></td>
                          <td class="center"><%= comment.get("user").get("molianId") %></td>
                          <td class="center"><%= comment.get("content") %></td>
                          <td class="center"><%= Format(comment.createdAt) %></td>
                          <td class="center">
                              <% if(comment.get("status")==1){ %>
                                  <span class="btn">已处理</span>    
                              <% } %>                               
                              <% if(comment.get("status")==0){ %>                                   
                                  <span class="btn btn-danger delete" commentId="<%=comment.id%>">
                                    <i class="glyphicon glyphicon-remove icon-white"></i>
                                    删除 
                                  </span>
                              <% } %>

                          </td>
                          <% } %>
                        </tr>
                      <% }) %>
                    <% } %>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <% include ./partials/footer %>
  </div>
  <% include ./partials/external %>
</body>
</html>
